@extends('common.company_template')

@section('content')
    <div class="boxWidth">
        @include('common.notice_msg')
        <div class="row searchLine">
            <div class="col-xs-6 ">
                <select id="cat" class="searchSelect">
                    <option value="not">全部订单</option>
                    <option value="1">未使用</option>
                    <option value="0">已使用</option>
                </select>
                <button id="orderStatus" class="btn btn-default searchBtn">筛选</button>
            </div>
            {{--<div class="col-xs-6 searchInput">--}}
                {{--<input type="text" placeholder="请输入订单号" id="searchInput">--}}
                {{--<button class="btn btn-default searchBtn" id="searchCon">搜索</button>--}}
            {{--</div>--}}
        </div>
        <table class="table table-hover adminTableBg">
            <thead>
            <tr>
                <th class="col-xs-2">商户</th>
                <th class="col-xs-3">优惠码</th>
                <th class="col-xs-1">状态</th>
                <th class="col-xs-2">来源订单</th>
                <th class="col-xs-2">时间</th>
            </tr>
            </thead>
            <tbody>
            <?php $statusName = ['已使用','未使用']; ?>
            @foreach($codes as $g)
                <tr>
                    <th class="col-xs-2 itemTd">{{$g->name}}</th>
                    <th class="col-xs-3 itemTd">{{$g->code}}</th>
                    <th class="col-xs-1 itemTd">{{$statusName[$g->status]}}</th>
                    <th class="col-xs-2 itemTd"><a href="https://sichuangyi.demopp.in/shop/orders/{{$g->order_id}}" target="_blank">{{$g->order}}</a></th>
                    <th class="col-xs-2 itemTd">{{$g->created_at}}</th>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div class="pull-right">
            <?php
            $s=isset($_GET['s'])?$_GET['s']:'';
            $status=isset($_GET['status'])?$_GET['status']:'';
            if($s){
                $url = ['s' => $s];
            }elseif($status){
                $url = ['status' => $status];
            }else{
                $url = [];
            }
            ?>
            {!! $codes->appends($url)->render() !!}
        </div>
    </div>
@stop
@section('js')
    <script>
        (function () {
            {{--$('#searchCon').on('click',function () {--}}
                {{--var url = $('#searchInput').val().replace(/(^\s*)|(\s*$)/g, "");--}}
                {{--if(url){--}}
                    {{--window.location.href= "{!! url('admin/orders?s=') !!}"+url;--}}
                {{--}else{--}}
                    {{--window.location.href= "{!! url('admin/orders') !!}"--}}
                {{--}--}}
            {{--});--}}
            $('#orderStatus').on('click',function () {
                var cat = $('#cat').val();
                if(cat!='not'){
                    window.location.href= "{!! url('admin/shopcode?status=') !!}"+cat;
                }else{
                    window.location.href= "{!! url('admin/shopcode') !!}"
                }
            });
        })()
    </script>
@stop